<?php

namespace app\admin\model\shopro\user;

use app\admin\model\shopro\Common;

class WalletLog extends Common
{
    protected $name = 'shopro_user_wallet_log';

    protected $updateTime = false;

    protected $type = [
        'ext' => 'json'
    ];
    // 追加属性
    protected $append = [
        'event_text'
    ];

    const TYPE_MAP = [
        'money' => '消费券',
        'score' => '贡献值',
        'commission' => '福利券',
        'gold_bean'  => '金豆',
        'shopping_score' => '购物积分',
        'tokens' => '鹿宝'
    ];

    protected $eventMap = [
        'score' => [
            'signin' => '签到-赠送贡献值',
            'replenish_signin' => '签到-补签',
            'activity_gift' => '活动-赠送贡献值',
            'score_shop_pay' => '贡献值商城-贡献值支付',
            'order_pay' => '商城订单-贡献值抵扣',
            'order_refund' => '订单退款-退还贡献值',
            'admin_recharge' => '后台-贡献值充值',
            'recharge_gift' => '线上充值-赠送贡献值'
        ],
        'money' => [
            'order_pay' => '商城订单-消费券支付',
            'order_recharge' => '线上充值',
            'admin_recharge' => '后台-消费券充值',
            'recharge_gift' => '线上充值-赠送消费券',
            'activity_gift' => '活动-赠送消费券',
            'order_refund' => '订单退款-退还消费券',
            'transfer_by_commission' => '福利券-转入到消费券'
        ],
        'commission' => [
            'withdraw' => '兑换',
            'withdraw_error' => '兑换失败-返还福利券',
            'reward_income' => '福利券-收益',
            'reward_back' => '福利券-退还',
            'transfer_to_money' => '福利券-转出到消费券',
            'order_pay' => '商城订单-福利券支付',
        ],
        'gold_bean' => [
            'withdraw' => '兑换',
            'order_pay' => '商城订单-金豆支付',
        ],
        'tokens' => [
            'withdraw' => '兑换',
            'order_pay' => '商城订单-通证支付',
        ],
        'shopping_score' => [
            'withdraw' => '兑换',
            'order_pay' => '商城订单-购物积分支付',
        ],
    ];

    public function getEventMap() {
        return $this->eventMap;
    }

    public function scopeMoney($query)
    {
        return $query->where('type', 'money');
    }

    public function scopeCommission($query)
    {
        return $query->where('type', 'commission');
    }

    public function scopeGold_bean($query)
    {
        return $query->where('type', 'gold_bean');
    }
    public function scopeShopping_score($query)
    {
        return $query->where('type', 'shopping_score');
    }

    public function scopeScore($query)
    {
        return $query->where('type', 'score');
    }

    public function getEventTextAttr($value, $data)
    {
        return $this->eventMap[$data['type']][$data['event']] ?? '';
    }
}
